const net = require("net");
const protobuf = require ("protobufjs");//不引入报错
const sumProto = require("./Sum_pb"); 
 
let s=new sumProto.Sum();

const sumServer=net.createServer((socket)=>{
    //sumServer.maxConnections=3
    socket.on("data",(data)=>{
        const object=sumProto.Sum.deserializeBinary(data)
        const sum=object.getAddend()+object.getAugend()
        /* s.setAddend(sum)
        s.setAugend(2)
        const deserializeSum=s.serializeBinary()
        console.log(sum+"=="+deserializeSum)   */
        
        socket.write(sum.toString())
        socket.destroy()
    })

    socket.on("error",(ex)=>{
        console.log(ex)
        
     })
})

sumServer.listen(8090,function(){
     
})

module.exports={
    sumServer
}